import React from "react";
import CmtBox from "./CmtBox";
import CmtItem3 from "./CmtItem3";
export default class CmtList extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      list: [
        {
          user: "zx",
          content: "123",
        },
        {
          user: "ll",
          content: "456",
        },
        {
          user: "zb",
          content: "788",
        },
      ],
    };
  }
  componentWillMount() {
    this.loadCmts();
  }

  render() {
    return (
      <div>
        <h1>这是评论组件</h1>
        <CmtBox reload={this.loadCmts}></CmtBox>
        {this.state.list.map((item, i) => {
          return <CmtItem3 key={i} {...item}></CmtItem3>;
        })}
      </div>
    );
  }
  // 从本地localstorage中加载
  loadCmts = () => {
    let list = JSON.parse(localStorage.getItem("cmts" || "[]"));
    this.setState({
      list,
    });
  };
}
